import { Component, OnInit } from '@angular/core';
import { DefaultService } from '../../api';
import { ActivatedRoute, Router } from '@angular/router';
import { UserService } from '../user.service';
import { SockJsService } from '../sock-js.service';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {

  constructor(private api:DefaultService,private router:Router,private active:ActivatedRoute,private me:UserService,private sockJs:SockJsService) { }

  ngOnInit() {
  }

  login(email:string,password:string){
    this.active.queryParams.subscribe(value=>{
      const go = (value['go']===undefined || value['go']===null)?'/device':value['go'];
      this.api.getLogin(email,password).subscribe(result=>{
        if(result.status==1){
          this.router.navigateByUrl(go);
        }else{
          alert(result.message)
        }
      })
    });

  }


}
